function a(a, t, e) {
    return t in a ? Object.defineProperty(a, t, {
        value: e,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : a[t] = e, a;
}

var t = getApp(), e = require("../../utils/api.js");

Page({
    data: {
        optionList: [ {
            status: 0,
            name: "全部",
            code: 0
        }, {
            status: 10,
            name: "待付款",
            code: 1
        }, {
            status: 20,
            name: "备货中",
            code: 2
        }, {
            status: 30,
            name: "待收货",
            code: 3
        }, {
            status: 100,
            name: "已完成",
            code: 4
        } ],
        containerHeight: 0,
        scrollTop: 0,
        currentTab: 0,
        curCode: 0,
        data: [],
        loading: !1,
        page: 2,
        showLoding: !0,
        dataLength: 1
    },
    onLoad: function(o) {
        var n = wx.getSystemInfoSync(), r = this, d = 0;
        if (r.setData({
            showLoding: !r.data.showLoding
        }), "" != o.id && void 0 != o.id) {
            var s = o.id;
            10 == s ? d = 1 : 20 == s ? d = 2 : 30 == s ? d = 3 : 100 == s && (d = 4);
        }
        this.setData({
            currentTab: o.id ? o.id : 0,
            curCode: d,
            containerHeight: n.windowHeight - Math.round(n.windowWidth / 375 * 55)
        }), console.log(0, r.data.currentTab), e.getOrder({
            openid: t.globalData.openid,
            status: o.id
        }).then(function(t) {
            console.log(t);
            var e = t.data;
            r.setData({
                data: t.data,
                showLoding: !r.data.showLoding
            });
            for (var o = 0; o < e.length; o++) {
                for (var n = e[o].item_goods, d = 0, s = 0; s < n.length; s++) {
                    var i = "data[" + o + "].all_num";
                    d += parseInt(n[s].oss_g_num);
                }
                r.setData(a({}, i, d));
            }
            console.log(r.data.data), 0 == r.data.data.length && r.setData({
                dataLength: 0
            });
        }), wx.setNavigationBarColor({
            frontColor: wx.getStorageSync("basic").topcolor,
            backgroundColor: wx.getStorageSync("basic").topbg
        });
    },
    switchNav: function(o) {
        var n, r = this, d = o.currentTarget.dataset.current, s = r.data.optionList;
        r.setData({
            showLoding: !r.data.showLoding,
            dataLength: 1,
            click: 1
        });
        for (var i = 0; i < s.length; i++) d == s[i].status && (n = i);
        r.setData({
            currentTab: d,
            curCode: n,
            data: []
        }), console.log(d), e.getOrder({
            openid: t.globalData.openid,
            status: d
        }).then(function(t) {
            console.log(t);
            var e = t.data;
            r.setData({
                data: t.data,
                showLoding: !r.data.showLoding,
                click: 0
            });
            for (var o = 0; o < e.length; o++) {
                for (var n = e[o].item_goods, d = 0, s = 0; s < n.length; s++) {
                    var i = "data[" + o + "].all_num";
                    d += parseInt(n[s].oss_g_num);
                }
                r.setData(a({}, i, d));
            }
            console.log(r.data.data), 0 == r.data.data.length && r.setData({
                dataLength: 0
            });
        });
    },
    bindChange: function(o) {
        var n = this;
        if (1 == n.data.click) return !1;
        var r = o.detail.current, d = n.data.optionList;
        console.log(r);
        for (var s, i = 0; i < d.length; i++) r == i && (s = d[i].status);
        n.setData({
            currentTab: s,
            data: [],
            dataLength: 1
        }), console.log(s), e.getOrder({
            openid: t.globalData.openid,
            status: s
        }).then(function(t) {
            console.log(t);
            var e = t.data;
            n.setData({
                data: t.data
            });
            for (var o = 0; o < e.length; o++) {
                for (var r = e[o].item_goods, d = 0, s = 0; s < r.length; s++) {
                    var i = "data[" + o + "].all_num";
                    d += parseInt(r[s].oss_g_num);
                }
                n.setData(a({}, i, d));
            }
            0 == n.data.data.length && n.setData({
                dataLength: 0
            });
        });
    },
    getCurrentList: function(o) {
        var n = this;
        n.setData({
            loading: !0,
            tip: ""
        }), e.getOrder({
            openid: t.globalData.openid,
            status: n.data.currentTab,
            page: n.data.page
        }).then(function(t) {
            console.log(t);
            var e = n.data.page + parseInt(1), o = n.data.data.concat(t.data);
            if (0 == t.errno) {
                n.setData({
                    data: o,
                    page: e,
                    loading: !1
                });
                for (var r = 0; r < o.length; r++) {
                    for (var d = o[r].item_goods, s = 0, i = 0; i < d.length; i++) {
                        var g = "data[" + r + "].all_num";
                        s += parseInt(d[i].oss_g_num);
                    }
                    n.setData(a({}, g, s));
                }
            } else wx.showToast({
                title: "已显示全部订单",
                icon: "loading",
                duration: 1500
            }), n.setData({
                loading: !1
            });
        });
    },
    viewDetail: function(a) {
        var t = a.currentTarget.dataset.orderid, e = a.currentTarget.dataset.allnum;
        wx.navigateTo({
            url: "/pages/order/orderDetail?id=" + t + "&&allnum=" + e
        });
    }
});